home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue36 / alfresco / TestSrch.dpr < prev   
Encoding:
Text File  |  1998-07-03  |  2.4 KB  |  101 lines

  1. program TestSrch;
  2.  
  3. {$IFNDEF Win32}
  4. !! Sorry, this program can only be compiled in 32-bits
  5. {$ENDIF}
  6.  
  7. {$APPTYPE CONSOLE}
  8.  
  9. uses
  10.   Windows,
  11.   SysUtils,
  12.   BMSearch in 'BMSearch.pas';
  13.  
  14. var
  15.   TextBlock : string;
  16.  
  17. procedure FindWithPos(aWord : string);
  18. var
  19.   PosWord : integer;
  20.   StartTime : integer;
  21.   i         : integer;
  22. begin
  23.   writeln('Searching for [', aWord, '] with Pos');
  24.   StartTime := GetTickCount;
  25.   for i := 1 to 5000 do
  26.     PosWord := Pos(aWord, TextBlock);
  27.   writeln(GetTickCount - StartTime);
  28. end;
  29.  
  30. procedure FindWithBMPos(aWord : string);
  31. var
  32.   PosWord : integer;
  33.   StartTime : integer;
  34.   i         : integer;
  35. begin
  36.   writeln('Searching for [', aWord, '] with Boyer-Moore Pos');
  37.   StartTime := GetTickCount;
  38.   for i := 1 to 5000 do
  39.     PosWord := BMPosSimple(aWord, TextBlock);
  40.   writeln(GetTickCount - StartTime);
  41. end;
  42.  
  43. procedure FindWithBMPosEx(aWord : string);
  44. var
  45.   PosWord : integer;
  46.   StartTime : integer;
  47.   i         : integer;
  48. begin
  49.   writeln('Searching for [', aWord, '] with Boyer-Moore Pos');
  50.   StartTime := GetTickCount;
  51.   for i := 1 to 5000 do
  52.     PosWord := BMPos(aWord, TextBlock, true, 1);
  53.   writeln(GetTickCount - StartTime);
  54. end;
  55.  
  56. var
  57.   FSize : integer;
  58.   F : file;
  59.  
  60. begin
  61.   Assign(F, 'LLL.TXT');
  62.   Reset(F, 1);
  63.   FSize := FileSize(F);
  64.   SetLength(TextBlock, FSize);
  65.   BlockRead(F, TextBlock[1], FSize);
  66.   Close(F);
  67.  
  68.   writeln(Pos('keel', TextBlock));
  69.   writeln(BMPosSimple('keel', TextBlock));
  70.   writeln(BMPos('KEEL', TextBlock, true, 1));
  71.   writeln(Pos('keep', TextBlock));
  72.   writeln(BMPosSimple('keep', TextBlock));
  73.   writeln(BMPos('KEEP', TextBlock, true, 1));
  74.   writeln(Pos('keek', TextBlock));
  75.   writeln(BMPosSimple('keek', TextBlock));
  76.   writeln(BMPos('KEEK', TextBlock, true, 1));
  77.   writeln(Pos('tongues of mocking wenches', TextBlock));
  78.   writeln(BMPosSimple('tongues of mocking wenches', TextBlock));
  79.   writeln(BMPos('TONGUES OF MOCKING WENCHES', TextBlock, true, 1));
  80.  
  81.   FindWithPos('keel');
  82.   FindWithBMPos('keel');
  83.   FindWithPos('keep');
  84.   FindWithBMPos('keep');
  85.   FindWithPos('keek');
  86.   FindWithBMPos('keek');
  87.   FindWithPos(' keel');
  88.   FindWithBMPos(' keel');
  89.   FindWithPos(' keep');
  90.   FindWithBMPos(' keep');
  91.   FindWithPos(' keek');
  92.   FindWithBMPos(' keek');
  93.  
  94.   FindWithPos('tongues of mocking wenches');
  95.   FindWithBMPos('tongues of mocking wenches');
  96.   FindWithBMPosEx('TONGUES OF MOCKING WENCHES');
  97.  
  98.   readln;
  99. end.
  100.  
  101.